package com.shuhg.book.tool
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.CapsStyle;
	import flash.display.IBitmapDrawable;
	import flash.display.LineScaleMode;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	import mx.controls.Image;
	
	import shg.book.size.BookData;
	import shg.book.util.BorderImage;

	public class DrawAnnotate
	{
		//选择花纹
		[Embed(source="assets/image/flower/0.png")]
		public static  const flower0:Class;
		[Embed(source="assets/image/flower/1.png")]
		public static  const flower1:Class;
		[Embed(source="assets/image/flower/2.png")]
		public static  const flower2:Class;
		[Embed(source="assets/image/flower/3.png")]
		public static  const flower3:Class;
		[Embed(source="assets/image/flower/4.png")]
		public static  const flower4:Class;
		[Embed(source="assets/image/flower/5.png")]
		public static  const flower5:Class;
		[Embed(source="assets/image/flower/6.png")]
		public static  const flower6:Class;
		[Embed(source="assets/image/flower/7.png")]
		public static  const flower7:Class;
		[Embed(source="assets/image/flower/8.png")]
		public static  const flower8:Class;
		
		public function DrawAnnotate()
		{
		}
		/**
		 * 绘制铅笔
		 * _width 宽
		 * _height 高
		 * _postil 绘制对象
		 * _localX  起始X轴
		 * _localY  起始Y轴
		 * */
		public static function drawPencil(_width:Number,_height:Number,_postil:Image,_localX:Number,_localY:Number):BorderImage{
			_postil.graphics.clear();
			var s:Sprite=new Sprite();
			s.graphics.lineStyle(BookData.lineSize, BookData.lineColor, BookData.lineAlpha);
			s.graphics.moveTo(0, 0);
			s.graphics.lineTo(_width, _height);
			//外层
			s.graphics.lineStyle(20, BookData.lineColor, 0);
			s.graphics.moveTo(0, 0);
			s.graphics.lineTo(_width, _height);
			//构建位图
			var pencil:BorderImage =new BorderImage();
			pencil.addChild(s);
			pencil.width=_width;
			pencil.height=_height;
			pencil.x=_localX;
			pencil.y=_localY;
			return pencil;
		}
		/**
		 * 绘制刷子
		 * */
		public static function drawBrush(_width:Number,_height:Number,_postil:Image,_localX:Number,_localY:Number):BorderImage{
			_postil.graphics.clear();
			var s:Sprite=new Sprite();
			s.graphics.lineStyle(30,BookData.lineColor,BookData.lineAlpha,true,LineScaleMode.VERTICAL,CapsStyle.SQUARE);
			s.graphics.moveTo(0,_height/2);
			s.graphics.lineTo(_width,_height/2);
			
			var brush:BorderImage =new BorderImage();
			brush.addChild(s);
			brush.width=_width;
			brush.height=_height;
			brush.x=_localX;
			brush.y=_localY;
			return brush;
		}
		/**
		 * 绘制钢笔
		 * */
		public static function drawPen(_width:Number,_height:Number,_postil:Image,_localX:Number,_localY:Number):BorderImage{
			_postil.graphics.clear();
			var s:Sprite=new Sprite();
			s.graphics.lineStyle(BookData.lineSize,BookData.lineColor,BookData.lineAlpha);
			s.graphics.moveTo(0,_height/2);
			s.graphics.lineTo(_width,_height/2);
			//外层
			s.graphics.lineStyle(20,BookData.lineColor,0);
			s.graphics.moveTo(0,_height/2);
			s.graphics.lineTo(_width,_height/2);
			
			var pen:BorderImage =new BorderImage();
			pen.addChild(s);
			pen.width=_width;
			pen.height=_height;
			pen.x=_localX;
			pen.y=_localY;
			return pen;
		}
		/**
		 * 花纹
		 * index 指定索引的画刷
		 * _x	X轴坐标
		 * _y	Y轴坐标
		 * _width	批注宽度
		 * _height	批注高度
		 * */
		public static function drawFlower(index:Number,_width:Number,_height:Number,_localX:Number,_localY:Number):BorderImage{
			var s:Sprite=new Sprite();
			s.graphics.beginBitmapFill(createBitmapData(index));
			s.graphics.drawRect(0,0,_width,_height);
			s.graphics.endFill();
			var flower:BorderImage=new BorderImage();
			flower.addChild(s);
			flower.width=_width;
			flower.height=_height;
			flower.x=_localX;
			flower.y=_localY;
			return flower;
		}
		/**
		 * 点式批注
		 * */
		public static function drawPoint(_mouseX:Number,_mouseY:Number,pointCursor:Class):BorderImage{
			var point:BorderImage=new BorderImage();
			point.source=pointCursor;
			point.x=_mouseX;
			point.y=_mouseY;
			return point;
		}
		/**
		 * 
		 * 根据选择创建位图
		 * */
		public static function createBitmapData(index:Number):BitmapData{
			var bitMap:BitmapData;
			switch(index){
				case 0:
					bitMap=new flower0().bitmapData;
					break;
				case 1:
					bitMap=new flower1().bitmapData;
					break;
				case 2:
					bitMap=new flower2().bitmapData;
					break;
				case 3:
					bitMap=new flower3().bitmapData;
					break;
				case 4:
					bitMap=new flower4().bitmapData;
					break;
				case 5:
					bitMap=new flower5().bitmapData;
					break;
				case 6:
					bitMap=new flower6().bitmapData;
					break;
				case 7:
					bitMap=new flower7().bitmapData;
					break;
				case 8:
					bitMap=new flower8().bitmapData;
					break;
				default:
					bitMap=new flower0().bitmapData;
			}
			return bitMap;
		}
	}
}